package com.neusoft.dibuy;

import java.util.*;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) {
        int[] is = {1, 2, 0, 1, 0, 2, 0, 3, 5, 6, 7, 0};
        int left = 0;
        int right = 0;
        do {
//        找到第一个0的位置
            while (left < is.length && is[left] != 0) {
                left++;
            }
            right = left + 1;
            while (right < is.length && is[right] == 0) {
                right++;
            }
            if (right < is.length) {
                int temp = is[left];
                is[left] = is[right];
                is[right] = temp;
            }
            left++;
            right++;
        } while (left < is.length && right < is.length);
        System.out.println(Arrays.toString(is));
    }

    public static void main5(String[] args) {
        int[] is1 = {1, 3, 5, 7, 9};
        int[] is2 = {-1, 0, 2, 4, 6, 8, 10, 11, 12};
        int[] is3 = new int[is1.length + is2.length];
        int s1 = 0;
        int s2 = 0;
        int t = 0;
        while (s1 < is1.length && s2 < is2.length) {
            if (is1[s1] < is2[s2]) {
                is3[t] = is1[s1];
                s1++;
            } else {
                is3[t] = is2[s2];
                s2++;
            }
            t++;
        }

        if (s2 < is2.length) {
            while (s2 < is2.length) {
                is3[t] = is2[s2];
                s2++;
                t++;
            }
        } else {
            while (s1 < is1.length) {
                is3[t] = is1[s1];
                s1++;
                t++;
            }
        }


        System.out.println(Arrays.toString(is3));


    }

    public static void main4(String[] args) {
//
//        Scanner sc = new Scanner(System.in);
//        String s = sc.nextLine(); // 499
        String s = "999";
        String[] ss = s.split(""); //  9,9,9
        int[] is = new int[ss.length + 1];
        is[0] = 0;
        for (int i = 0; i < ss.length; i++) {
            is[i + 1] = Integer.parseInt(ss[i]);
        }
        int add1 = 0;
        int right = is.length - 1;
        do {
            int i = is[right] + 1;
            if (i == 10) {
                is[right] = 0;
                right--;
            } else {
                is[right] = i;
                break;
            }
        } while (1 == 1);
        System.out.println(Arrays.toString(is));
    }


    public static void main3(String[] args) {
        int[] is = {1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 5, 6, 7, 7, 7, 8, 9, 9};
        int left = 0;
        int right = 1;
        while (right < is.length) {
            if (is[left] != is[right]) {
                left++;
                if (left != right)
                    is[left] = is[right];
            } else {
                right++;
            }
        }
        left++;
        for (; left < is.length; left++) {
            is[left] = 0;
        }
        System.out.println(Arrays.toString(is));
    }


    public static void main2(String[] args) {
        int target = 93;
        int[] is = {45, 63, 89, 0, 6, 4, 5, 9, 8, 0, 89, 45, 6, 7, 8, 9, 0, 456, 378, 4567, 95, 4, 6, 8, 9, 7};
//        hash
        Map map = new HashMap<Integer, List<Integer>>();
        for (int i = 0; i < is.length; i++) {
            int key = is[i];
            List list = null;
            Object o = map.get(key);
            if (o == null) {
                list = new ArrayList<Integer>();
                map.put(key, list);
            } else {
                list = (List) o;
            }
            list.add(i);
        }
        Set<Integer> keys = map.keySet();
        for (Integer key : keys) {
            int key2 = target - key;
            Object o = map.get(key2);
            if (o != null) {
                List<Integer> list1 = (List) o;
                List<Integer> list2 = (List) map.get(key);
                for (Integer i1 : list1) {
                    for (Integer i2 : list2) {
                        System.out.println(" i1 =   " + i1 + " , i2 = " + i2);
                    }
                }

            }
        }
        System.out.println("Hello World!");
    }


    public static void main1(String[] args) {
        int[] is = {7, 9, 6, 2, 5, 1, 0, 3, 8, 4};
        int target = 7;
        for (int i = 0; i < is.length - 1; i++) {
            if (is[i] > target)
                continue;
            for (int j = i + 1; j < is.length; j++) {
                if (is[i] + is[j] == target) {
                    System.out.println(" i =   " + i + " , j = " + j);
                }
            }
        }
        System.out.println("Hello World!");
    }
}
